<?php
include('./include/conn.php');
if(isset($_SESSION['U'])){
	echo "<script>alert('发布话题，请登录！');window.location.href='login.php';</script>";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>讨论组 BBS</title>
 	<link rel="stylesheet" type="text/css" href="./include/style.css">
  	<script>
  		function check_add(){
  			if (add_form.title.value.length == 0) {
  				alert('标题必填！');
  				return add_form.title.focus();
  			}else if (add_form.author.value.length == 0) {
  				alert('作者必填！');
  				return add_form.author.focus();
  			}else if(add_form.content.value.length == 0){
  				alert('内容必填！');
  				return add_form.content.focus();
  			}else{
  				add_form.submit();
  			}
  		}
  	</script>
</head>
<body>
	<div class="container">
		<header>
			<h1>讨论组 BBS</h1>
		</header>
		<nav>
			<div class="search">
				<form method="post" action="search.php">
				<input type="text" class="w" name="w"><input type="submit" class="seach_btn" value="搜索">
				</form>
			</div>
			<ul>
				<?php if (isset($_SESSION['u'])) {
					echo"<li id='userid'>".strtoupper($_SESSION['u'])."</li>";
					echo"<li><a href='logout.php'>登出</a></li>";
				}else{ ?>
					<li><a href="login.php" title="登录">登录</a></li>
					<li><a href="login.php" title="注册">注册</a></li>
				<?php } ?>
			</ul>
		</nav>
		<form method="post" name="add_form" action="add_ok.php">
			<article>
				<div class="add_title"><input type="text" class="title" name="title" placeholder="请出入标题"></div>
				<div class="add_author"><input type="text" class="author" name="author" value="<?php if(isset($_SESSION['u'])) echo $_SESSION['u'];?>"></div>
				<textarea name="content" placeholder="话题内容"></textarea>
				<div><input type="button" id="addbtn" value="添加" onclick="check_add()"></div>
			</article>
		</form>
	</div>
</body>
</html>